<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>发票</title>
    <link rel="stylesheet" href="../../layuiadmin/js/finance/js/bootstrap/css/bootstrap.min.css" />
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.min.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/bootstrap/js/bootstrap.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.cookie.js"></script>
    <script>
        $(document).ready(function () {
            $.post("http://localhost:8080/financePayoutController/caseid",function(msg){
                for(var i=0;i<msg.length;i++){
                    var caseid=$("#caseid");
                    if(msg[i].ppid==0){
                        var op=$("<option value='"+msg[i].caseTypeid+"'>"+msg[i].typeName+"</option>");
                    }else{
                        var op=$("<option value='"+msg[i].caseTypeid+"'>" + "&nbsp&nbsp----" +msg[i].typeName+"</option>");
                    }
                    caseid.append(op);
                }
            });
            $.post("http://localhost:8080/financeInvoiceController/openproject",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var openproject=$("#openproject");
                    var op=$("<option value='"+msg[i].openProjectId+"'>"+msg[i].project+"</option>");
                    openproject.append(op);
                }
            });
            $.post("http://localhost:8080/financeInvoiceController/invoicetypelist",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var invoicetype=$("#invoicetype");
                    var op=$("<option value='"+msg[i].invoiceTypeId+"'>"+msg[i].invoiceType+"</option>");
                    invoicetype.append(op);
                }
            });
            list();
        });
        function list() {
            var cookie = $.cookie("redisName");
            var caselawid = $("#caselawid").val();
            var opentype = $("#opentype").val();
            var invoicetype = $("#invoicetype").val();
            var openproject = $("#openproject").val();
            var caseid = $("#caseid").val();
            var inputdate = $("#inputdate").val();
            var enteringdate = $("#enteringdate").val();
            $.post("http://localhost:8080/financeInvoiceController/invoicelist",
                {
                    "caselawid": caselawid,
                    "opentype": opentype,
                    "invoicetype": invoicetype,
                    "openproject": openproject,
                    "caseid": caseid,
                    "inputdate": inputdate,
                    "enteringdate": enteringdate,
                    "cookie":cookie
                },
                function (msg) {
                    var tab = $("#tab");
                    if (msg.length == 0) {
                        $("#tab  tr:not(:first)").remove();
                        var tr = $("<tr></tr>");
                        var td = $("<td colspan='7'>没有相关数据</td>");
                        tr.append(td);
                        tab.append(tr);
                        var caselawid = $("#caselawid").val("");
                        var inputdate = $("#inputdate").val("");
                        var enteringdate = $("#enteringdate").val("");
                    } else {
                        $("#tab  tr:not(:first)").remove();
                        var sum = 0;
                        var tr1 = $("<tr></tr>");
                        for (var i = 0; i < msg.length; i++) {
                            //applectionDate时间
                            var myDate = new Date(msg[i].applectionDate);
                            var year=myDate.getFullYear();
                            var month=myDate.getMonth()+1;
                            var date=myDate.getDate();
                            var now=year+'-'+month+"-"+date;
                            //invoiceDate时间
                            var myDate1 = new Date(msg[i].invoiceDate);
                            var year=myDate.getFullYear();
                            var month=myDate.getMonth()+1;
                            var date=myDate.getDate();
                            var now1=year+'-'+month+"-"+date;
                            var tr = $("<tr></tr>");
                            var td=$("<td class='hidden'>"+msg[i].invoiceId+"</td>");
                            var td1 = $("<td>" + msg[i].caseId.caseId + "</td>>");
                            var td2 = $("<td>" + msg[i].invoiceTitle + "</td>>");
                            var td3 = $("<td>" + msg[i].invoiceMoney + "</td>>");
                            var td4 = $("<td>" + now + "</td>>");
                            var td5 = $("<td>" + now1 + "</td>>");
                            var td7 = $("<td>" +
                                "<div class='dropdown'>" +
                                "<button class='btn btn-default' type='button' id='drop' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true'>" +
                                "操作<span class='caret'></span>" +
                                "</button>" +
                                "<ul class='dropdown-menu' aria-labelledby='drop'>" +
                                "<li><a onclick='look(this)'>查看</a></li>" +
                                "<li><a onclick='addpay(this)'>添加收款记录</a></li>" +
                                "<li><a onclick='del(this)'>删除</a></li>" +
                                "</ul>" +
                                "</div>" +
                                "</td>")
                            var invoiceStatus = "";
                            if (msg[i].invoiceStatus == 'Y') {
                                invoiceStatus = "未开";
                            } else {
                                invoiceStatus = "已开";
                            }
                            var td6 = $("<td >" + invoiceStatus + "</td>>");
                            tr.append(td);
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tr.append(td7);
                            tab.append(tr);
                            sum += msg[i].invoiceMoney;
                        }
                        tr1.append("<td>总计收支金额</td>");
                        tr1.append("<td colspan='6'>" + sum + "(元)</td>");
                        tab.append(tr1);
                    }
                });
        }
        function update(obj){
            var invoiceId=$(obj).parent().parent().find("td").eq(0).text();
            $.post("http://localhost:8080/financeInvoiceController/update",{"invoiceId":invoiceId},function () {
                list();
            });
        }
        function del(obj) {
            var invoiceId=$(obj).parent().parent().parent().parent().parent().find("td").eq(0).text();
            alert(invoiceId);
            $.post("http://localhost:8080/financeInvoiceController/del",{"invoiceId":invoiceId},function () {
                list();
            });
        }
        function addpay(obj) {
            var caseid=$(obj).parent().parent().parent().parent().parent().find("td").eq(1).text();
            $.post("http://localhost:8080/financeIncomeController/caselist",{"caseid":caseid},function (msg) {
                window.location.href = "../../views/finance/casepayoutlist.html?caseid=" + caseid + "&overpay=" + msg.amountMoney + "";
            });
        }
        function look(obj) {
            var invoiceId=$(obj).parent().parent().parent().parent().parent().find("td").eq(0).text();
            window.location.href = "../../views/finance/lookinvoice.html?invoiceId="+invoiceId+"";
        }
    </script>

</head>
<body>
<div class="container-fluid">
    <form class="form-horizontal form-inline" >
        <div class="row" style="margin-top: 15px">
            <div class="col-lg-12">
                <input class="form-control" type="text" id="caselawid" placeholder="案号"/>
                <select class="form-control" id="opentype">
                    <option value="-1">请选择开票状态类型</option>
                    <option value="Y">已开</option>
                    <option value="N">未开</option>
                </select>
                <select class="form-control" id="invoicetype">
                    <option value="-1">请选择发票类型</option>
                </select>
                <select class="form-control" id="openproject">
                    <option value="-1">请选择开票项目类型</option>
                </select>
                <select class="form-control" id="caseid">
                    <option value="-1">请选择案件类型</option>
                </select>
                <label for="inputdate">申请时间</label>
                <input class="form-control" type="date" id="inputdate"/>
                <div style="margin-top: 15px">
                    <label for="enteringdate">开票时间</label>
                    <input class="form-control" type="date" id="enteringdate"/>
                    <button type="button" onclick="list()" class="btn btn-success">检索</button>
                </div>
            </div>
        </div>
        <div style="margin-top: 15px">
            <table class="table table-hover table-bordered" style="text-align: center" id="tab">
                <tr style="font-weight: bold">
                    <td>案号</td>
                    <td>发票抬头</td>
                    <td>发票金额(元)</td>
                    <td>申请日期</td>
                    <td>开票时间</td>
                    <td>开票状态</td>
                    <td>操作</td>
                </tr>
            </table>
        </div>
    </form>
</div>
</body>
</html>